package com.zmht.beike.biz.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zmht.beike.biz.SocialityBiz;
import com.zmht.beike.core.BaseBizImpl;
import com.zmht.beike.po.TLanguage;
import com.zmht.beike.po.TSociality;

public class SocialityBizImpl extends BaseBizImpl implements SocialityBiz {
	public boolean saveSociality(TSociality sociality){
		try{
			this.getSocialityDAO().saveObj(sociality);
		}catch(Exception e){
			return false;
		}
		return true;
		
	}

	public TSociality findById(Serializable id) {
		
		return (TSociality)this.getSocialityDAO().findById(TSociality.class, id);
	}

	public TSociality findByStudentId(Serializable studentId) {
		String hql = "from TSociality t where t.studentId="+studentId+" order by t.id desc";
		List<TSociality> list = this.getSocialityDAO().findByHQLObj(hql);
		if(list!=null&&list.size()>0){
			return list.get(0);
		}
		return null;
	}

	public boolean updateSociality(TSociality sociality) {
		try{
			this.getSocialityDAO().updateObj(sociality);
		}catch(Exception e){
			return false;
		}
		return true;
	}
	public static void main(String [] args){
		ApplicationContext cxt;
		cxt = new ClassPathXmlApplicationContext(new String[]{"spring/spring.xml","spring/spring_dao.xml","spring/spring_beike.xml"});
		SocialityBizImpl biz = (SocialityBizImpl)cxt.getBean("socialityBizTag");
		
		TSociality sociality = new TSociality();
		sociality.setStudentId(22);
		
		biz.saveSociality(sociality);
	}

	public List<TSociality> findByStudent(Serializable studentId,String startTime,String endTime) {
		String hql = "from TSociality t where t.studentId="+studentId;
		if(!"".equals(startTime)){hql += " and t.ctime>='"+startTime+"' ";}
		if(!"".equals(endTime)){hql += " and t.ctime<='"+endTime+"' ";}
		hql += " order by t.id desc";
		List<TSociality> list = this.getSocialityDAO().findByHQLObj(hql);

		return list;
	}
	
}
